package org.kjtc.controller;

import java.util.List;

import javax.annotation.Resource;

import org.kjtc.entity.BranchCompany;
import org.kjtc.entity.CarTeam;
import org.kjtc.entity.ChargingStation;
import org.kjtc.entity.DeviceObject;
import org.kjtc.entity.LineInfo;
import org.kjtc.entity.SubBranchCompany;
import org.kjtc.entity.UserInfo;
import org.kjtc.service.ListService;
import org.kjtc.service.UserInfoService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class ListController extends BaseController {
	
	@Resource(name = "listService")
	private ListService listService;

	@Resource(name = "userInfoService")
	private UserInfoService userInfoService;

	@Resource(name = "deviceObject")
    private DeviceObject deviceObject;

	@RequestMapping(value = "branchCompany")
	@ResponseBody
	public List<BranchCompany> getBranchCompany(){
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "下拉列表-运营司查询开始");
		List<BranchCompany> list = null;
		BranchCompany branchCompany = new BranchCompany();
//		branchCompany.setBranchCompanyID(this.getBranchCompanyID());
		try {
			list = listService.getBranchCompany(branchCompany);
		} catch (Exception e) {
			logger.error(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "下拉列表-运营查询异常:" + e.getMessage());
			return null;
		}
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "下拉列表-运营查询结束");
        return list;
	}
	
	/**
     * 车队
     * @return List
     * */
	@RequestMapping(value = "carTeam")
	@ResponseBody
	public List<CarTeam> car(String subBranchCompanyID){

		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "下拉列表-车队查询开始");
		List<CarTeam> list = null;
		CarTeam carTeam = new CarTeam();
	    try {
	    	carTeam.setSubBranchCompanyID(subBranchCompanyID);
	    	list = listService.getCarTeam(carTeam);
	    } catch(Exception e){
	    	logger.error(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "下拉列表-车队查询异常:" + e.getMessage());
	    	return null;
	    }

	    logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "下拉列表-车队查询结束");
	    return list;
	}

	/**
     * 线路名称
     * @return List
     * */
	@RequestMapping(value = "lineName")
	@ResponseBody
	public List<LineInfo> line(String teamID, String subBranchCompanyID, String branchCompanyID){

		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "下拉列表-线路名称查询开始");
		List<LineInfo> list = null;
		LineInfo lineInfo = new LineInfo();
		lineInfo.setTeamID(teamID);
		lineInfo.setSubBranchCompanyID(subBranchCompanyID);
		lineInfo.setBranchCompanyID(branchCompanyID);
	    try {
	    	list = listService.getLineInfo(lineInfo);
	    } catch(Exception e){
	    	logger.error(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "下拉列表-线路名称查询异常:" + e.getMessage());
	    	return null;
	    }

	    logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "下拉列表-线路名称查询结束");
	    return list;
	}

	@RequestMapping(value = "chargingStation")
	@ResponseBody
	public List<ChargingStation> getchargingStation(ChargingStation chargingStation){

		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "充电站名称列表查询开始");
		List<ChargingStation> chargingStationList = null;
		try {
			chargingStationList = listService.getChargingStationName(chargingStation);
		} catch (Exception e) {
			logger.error(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "充电站名称列表查询异常:" + e.getMessage());
			return null;
		}
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "充电站名称列表查询结束");
		return chargingStationList;
	}

	 /**
     * 分公司信息
     * @return List
     * */
	@RequestMapping(value = "subBranchCompany")
	@ResponseBody
    public List<SubBranchCompany> getSubBranchCompany(String branchCompanyID){

		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "分公司列表查询开始");
		List<SubBranchCompany> list = null;
		SubBranchCompany subBranchCompany = new SubBranchCompany();
		subBranchCompany.setBranchCompanyID(branchCompanyID);
        try {
        	list = listService.getSubBranchCompany(subBranchCompany);
        } catch(Exception e){
        	logger.error(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "分公司列表查询异常:" + e.getMessage());
        	return null;
        }

        logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "分公司列表查询结束");
        return list;
    }
	
	@RequestMapping(value = "userName")
	@ResponseBody
    public List<UserInfo> getUserName(String userID){

		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车队用户查询");
		List<UserInfo> list = null;
		UserInfo userInfo = new UserInfo();
		userInfo.setUserID(userID);
        try {
        	list = listService.getUserName(userInfo);
        } catch(Exception e){
        	logger.error(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "车队用户查询异常:" + e.getMessage());
        	return null;
        }

        return list;
    }
}